package org.jeecg.modules.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.common.constant.CommonCuckoo;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.entity.CuCommissionManagement;
import org.jeecg.modules.mapper.CuCommissionManagementMapper;
import org.jeecg.modules.service.ICuCommissionManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 提成管理
 * @Author: jeecg-boot
 * @Date: 2024-08-03
 * @Version: V1.0
 */
@Service
public class CuCommissionManagementServiceImpl extends ServiceImpl<CuCommissionManagementMapper, CuCommissionManagement> implements ICuCommissionManagementService {

    private final String REDIS_KEY = "commission_list";

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private CuCommissionManagementMapper mapper;


    @Override
    public List<CuCommissionManagement> getAll() {
        List<CuCommissionManagement> list = (List<CuCommissionManagement>) redisUtil.get(REDIS_KEY);
        if (ObjectUtil.isNotEmpty(list)) {
            return list;
        }

        QueryWrapper<CuCommissionManagement> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sorti");
        list = super.list(wrapper);
        if (ObjectUtil.isEmpty(list)) {
            return null;
        }
        redisUtil.set(REDIS_KEY, list, CommonCuckoo.CACHE_TIME);
        return list;
    }

    @Override
    public boolean save(CuCommissionManagement cuCommissionManagement) {
        redisUtil.removeAll(REDIS_KEY);
        return super.save(cuCommissionManagement);
    }

    @Override
    public boolean updateById(CuCommissionManagement cuCommissionManagement) {
        redisUtil.removeAll(REDIS_KEY);
        return super.updateById(cuCommissionManagement);
    }

    @Override
    public boolean removeById(String id) {
        redisUtil.removeAll(REDIS_KEY);
        return super.removeById(id);
    }

    @Override
    public boolean removeByIds(List<String> idList) {
        redisUtil.removeAll(REDIS_KEY);
        return super.removeByIds(idList);
    }
}
